<?php

declare(strict_types=1);

namespace app\controller\admin;

use app\model\admin\Banner;
use app\model\admin\CateModel;
use think\facade\Validate;
use think\Request;

class BannerController extends AdminBaseController
{
    public function getList(Request $request)
    {
        $params = $request->param();
        $member_user = $request->authInfo;
        $list = Banner::scope('where', $params)
            ->order('id', 'desc')
            ->paginate([
                'list_rows' => $this->limit,
                'page' => $this->page,
                'var_page' => $this->pageVar
            ]);

        return successPage($list);
    }
    public function add(Request $request)
    {
        $params = $request->param();
        // $member_user = $request->authInfo;
        // $user_id = $member_user['user_id'];

        // $params['sys_user_id'] = $user_id;
        $res = Banner::create($params);
        return success($res);
    }
    public function change(Request $request)
    {
        $params = $request->param();
        $res = Banner::update($params, ['id' => $params['id']]);
        return success($res);
    }
    public function del(Request $request)
    {
        $ids = input('ids');
        if (!is_array($ids)) {
            $ids = [$ids];
        }
        $res = Banner::destroy($ids);
        return success($res);
    }
}
